import { defineStore } from 'pinia'
import { reactive,toRefs } from 'vue'; 
import URI from '@/api/URI.js'
import NetCode from '@/api/NetCode.js'

export const demo1Store = defineStore('demo1', () => {
	const state = reactive({
		loading:false,
		dataGrid:[],
		paging:{//分页参数
			page:1,
			itemCount:0,
			pageCount:0,
			pageSize:5,
		}
	});
	
	function dataQuery(queryform = {}) {
		state.loading = true;
		this.$Http.post(URI.DEMO.LIST, queryform).then((data)=>{
			if(data.code == NetCode.SUCESS) {
				state.dataGrid = data.data.dataGrid;
				state.paging.page = data.data.page;
				state.paging.itemCount = data.data.itemCount;
				state.paging.pageCount = data.data.pageCount;
				state.paging.pageSize = data.data.pageSize;
				state.loading = false;
			} else {
				state.loading = false;
			}
		})
	}
	
	return {
		dataQuery,
		...toRefs(state),
	}
});